﻿using System.Collections.Generic;
using System.Linq;
using BLL.Services.Books;

namespace Web.Models
{
    public class CategoryBookModel
    {
        private readonly IEnumerable<BookShortInfoModel> _books;

        public CategoryBookModel(IEnumerable<BookShortInfoModel> books)
        {
            _books = books;
        }

        public object GetData(CategoryBookViewType viewType)
        {
            switch (viewType)
            {
                case CategoryBookViewType.Icon:
                    return _books.Select(
                        book => new
                        {
                            Id = book.BookId,
                            Name = book.BookTitle,
                            Avatar = book.BookImg
                        });

                case CategoryBookViewType.List:
                    return _books.Select(
                        book => new
                        {
                            Avatar = book.BookImg,
                            Id = book.BookId,
                            Name = book.BookTitle,
                            ShortDescription = book.ShortContent,
                            FileName = book.FileName,
                            IsCanRate = book.IsCanRate,
                            Rating = book.Rating
                        });

                default:
                    return null;
            }
        }

        public enum CategoryBookViewType
        {
            Icon = 0,
            List = 1
        }
    }
}